//
//  376. 摆动序列.swift
//  LeetCodeTrain
//
//  Created by rjb on 2021/7/20.
//  Copyright © 2021 rjb. All rights reserved.
//

import Foundation

class Solution376 {
    func wiggleMaxLength(_ nums: [Int]) -> Int {
        guard nums.count >= 1 else {
            return nums.count
        }
        var result = 1
        var preDiff = 0
        var curDiff = 0 // 以当前为标准，只关心上坡与下坡
        for i in 0..<(nums.count - 1) {
            curDiff = nums[i + 1] - nums[i]
            if (preDiff >= 0 && curDiff < 0) || (preDiff <= 0 && curDiff > 0) {
                result += 1
                preDiff = curDiff
            }
        }
        return result
    }
    
    static func test() {
        let nums = [1,17,5,10,13,15,10,5,16,8]
        let result = Solution376().wiggleMaxLength(nums)
        print(result)
    }
}
